//
//  RewardVideoAdM.m
//  TestDemo
//
//  Created by a on 2023/2/9.
//

#import "RewardVideoAdM.h"
#import <LDMobileAdSDK/LDMobileAdSDK.h>

@interface RewardVideoAdM ()<LDRewardVideoAdDelegate>

@property (nonatomic,strong)LDRewardVideoAd * ad;

@end

@implementation RewardVideoAdM


- (void)setupAd{
    [LDSDKConfig setAppKey:@"f7d19924efe93778" token:@"cvvcqdnyrk"];
    if(self.ad == nil){
        self.ad = [[LDRewardVideoAd alloc]initWithSlotID:@"0734791"];
        self.ad.viewController = self.viewController;
        self.ad.delegate = self;
    }
}

- (void)loadAdShow{
    [self setupAd];
    self.ad.viewController = self.viewController;
    [self.ad loadAdShow];
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        self.ad = nil;
//    });
}

- (void)loadAd{
    [self setupAd];
    [self.ad loadAd];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self showAd];
    });
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.ad = nil;
    });
}

- (void)showAd{
    self.ad.viewController = self.viewController;
    [self.ad showAd];
}

#pragma mark- LDRewardVideoAdDelegate
/// 激励视频加载完成
/// @param rewardVideoAd 广告实例
- (void)rewardVideoDidLoad:(LDRewardVideoAd *)rewardVideoAd{
    NSLog(@"---------%@",NSStringFromSelector(_cmd));
}

/// 激励视频加载失败
/// @param error 错误
- (void)rewardVideoFail:(LDRewardVideoAd *)rewardVideoAd error:(NSError *)error{
    NSLog(@"---------%@",NSStringFromSelector(_cmd));
}

///激励视频曝光
- (void)rewardVideoAdDidExposure:(LDRewardVideoAd *)rewardVideoAd{
    NSLog(@"---------%@",NSStringFromSelector(_cmd));
}

/// 激励视频触发点击
- (void)rewardVideoDidClick:(LDRewardVideoAd *)rewardVideoAd{
    NSLog(@"---------%@",NSStringFromSelector(_cmd));
}

/// 激励视频触发关闭
- (void)rewardVideoDidClose:(LDRewardVideoAd *)rewardVideoAd{
    NSLog(@"---------%@",NSStringFromSelector(_cmd));
}

///激励视频 播放达到激励条件达成
- (void)rewardVideoAdDidRewardEffective:(LDRewardVideoAd *)rewardVideoAd{
    NSLog(@"---------%@",NSStringFromSelector(_cmd));
}


- (void)dealloc{
    NSLog(@"RewardVideoAdM dealloc");
}
@end


